<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ page import="com.stone.para.IConstant"%>
<%
	String contextPath = request.getContextPath();
	com.stone.sys.pojo.TUser user = (com.stone.sys.pojo.TUser)session.getAttribute("SESSION_TUSER");
	com.stone.sys.pojo.TOrgan organ = (com.stone.sys.pojo.TOrgan)session.getAttribute("SESSION_TORGAN");
	String username=user.getName();	
%>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title><%=IConstant.PROGRAEM_TITLE%></title>
        <link rel="stylesheet" href="<%=contextPath%>/ext3/resources/css/ext-all.css" type="text/css"   />
        <link rel="stylesheet" href="<%=contextPath%>/css/main.css" type="text/css"  />
        <script src="<%=contextPath%>/ext3/adapter/ext/ext-base.js"></script>
        <script src="<%=contextPath%>/ext3/ext-all.js"></script>

        <script language="javascript">
            Ext.BLANK_IMAGE_URL = '<%=contextPath%>/ext3/resources/images/default/s.gif';
            Ext.QuickTips.init();
            Ext.form.Field.prototype.msgTarget = 'qtip';
            var cpath = '<%=contextPath%>';
            var username='<%=username%>';

			String.prototype.endWith=function(str){
				if(str==null||str==""||this.length==0||str.length>this.length)
				return false;
				if(this.substring(this.length-str.length)==str)
				return true;
				else
				return false;
				return true;
			}

			var username;
	
			var initData = function(){
			    Ext.get('close').on('click',function(){
			       window.location = '<%=contextPath%>/logout.do';
			        return false;
			    });
			};
			
			var buildLayout = function(){
			
				  var layout = new Ext.Viewport({
				        layout:'border',
				        items:[{
				            region:'north',
				            height:55,
				            contentEl:'banner'//,
				        },{
				            title:'当前用户: ' + username,
				            region:'west',
				            width:160,
				            split:true,
				            collapsible:true,
				            layout:'accordion',
				            collapseMode: 'mini',
				            defaults:{autoScroll:true,border:false},
				            layoutConfig:{
				                animate:true
				            }
				        },{
				            region:'center',
				            contentEl:'main-div'
				        }]
				    });
			
				    var store = new Ext.data.Store({
				        proxy:new Ext.data.HttpProxy({url:'login!getMenuByUserRole.do?parentID=0'}),
				        reader:new Ext.data.JsonReader({},['id','text','parentID','url']),
				        autoLoad:true
				    }).on('load',function(store,records){
			
				        var nav = layout.items.get(1);
				        
				        if (records != null && records != "") {
				        	
					        for (var i=0; i<records.length; i++){
					        	
					            var menu = new Ext.Panel({
					                id:records[i].data.id,
					                title:records[i].data.text//,
					               // iconCls:'nav'
					            });
			
					            var root = new Ext.tree.AsyncTreeNode({
					                id:records[i].data.id,
					                text:records[i].data.text,
					                leaf:false
					            });

					            var loader = new Ext.tree.TreeLoader({
					                        url : 'login!getMenuByUserRole.do?parentID='+ records[i].data.id
					                    });   
			
					            loader.on("beforeload", function(loader, node) { 
			
					            		if (node.id != root.id && !node.leaf) {
					            			loader.url = 'login!getMenuByUserRole.do?parentID='+ node.id;
					            		}
			
					                }); 
					           
					            var tree = new Ext.tree.TreePanel({
					            	id:'tree' + i,
					                loader:loader,//new Ext.tree.TreeLoader({dataUrl:'system/menu!getMenu.do?myCode='+ records[i].data.id}),
					                root:root,
					                border:false,
					                rootVisible:false,
							        useArrows:true,
							        autoScroll:true,
							        //animate:true,
							        //enableDD:true,
							        containerScroll: true
					            });
			
					            tree.on('click',function(node){
					                if (node.attributes.url != null && node.attributes.url != ''){ //node.isLeaf() != undefined && node.isLeaf()
					                	if (node.attributes.url.endWith(".do")|| node.attributes.url.endWith(".jsp")) {
					                    	Ext.get('main').dom.src = cpath + '/' + node.attributes.url + "?qxbtn=" + node.id + "&m=m";
					                    } else {
					                    if (node.attributes.url.endWith(".asp")) {
					                    	Ext.get('main').dom.src = node.attributes.url + "?username="+username;
					                         //alert(Ext.get('main').dom.src); 
					                       }else{
					                       Ext.get('main').dom.src = cpath + '/' + node.attributes.url + "&qxbtn=" + node.id + "&m=m";
					                      
					                       }
					                    }
					                    
					                   // alert(Ext.get('main').dom.src);
					                } else {
					                	//if (!node.isExpanded()) {
					                	//	node.expand();		
					                	//} else {
					                	//	node.collapse();
					                	//}              
					                }
					            });
					           
					           // root.expand(true);
					            menu.add(tree);
					            nav.add(menu);
					            
					 
					        }
					    }
				        layout.doLayout();
				    });
			
				};
			
			var init = function(){
				initData();
				username = Ext.get('username').dom.innerHTML;
				buildLayout();
			};
			
			Ext.onReady(init);
		
		</script>
	</head>
<body >
<div id="banner" style="background-image:url(<%=request.getContextPath()%>/images/topbar_bg.gif);width:100%">
	<table border="0" >
		<tr>
			<td >
				<img src="<%=request.getContextPath()%>/images/top001.gif">
			</td>
		</tr>
	</table>
</div>
<div id="top_menu">
	<table width="100%">
		<tr>
			<td align="right">
				<a href="#" id="close"><img src="<%=request.getContextPath()%>/images/close.gif" alt="重新登陆" /></a>&nbsp;&nbsp;&nbsp;
			</td>
		</tr>
		<tr>
			<td align="right">
				重新登录
			</td>
		</tr>
	</table>
</div>
	<div id="main-div" scrolling="no" style= "overflow:hidden">
		<iframe id="main" scrolling="no" frameborder="0" 
			style="width: 100%; height: 100%;" src="<%=request.getContextPath()%>/jsp/common/welcome.jsp" ></iframe>
	</div>
	<div id="username" class="x-hidden"><%=user.getName()%></div>
</body>
</html>